classdef my_sat  % 表示Point2是继承Point
   properties
       f ;  % 卫星频率
       sat;      
       describ = "自己创建的卫星对象";
   end
   properties(Access=public,Dependent=false)
       Tu;%卫星钟差
       satpos;%卫星每一时刻的位置速度
       satpos_post_res;
       timerange;
       satpos_sigma = 2;%卫星位置方差（m）
       satvel_sigma = 0.02;%卫星速度方差（m/s）
   end
   methods
       function obj = my_sat(sat,f,satpos)
          obj.f = f;
          obj.sat = sat;
          obj.satpos = satpos;
       end
      function obj = get_sat_ephemeris(obj,startime,endtime,samples)
        samples = seconds(samples);
        timeRange = startime : samples : endtime;    % 时间轴
        time_size = length(timeRange);
        disp("正在获取卫星位置速度(ecef)");
        h = waitbar(0, '正在获取卫星位置速度...');
        numSatellites = numel(obj.sat);
        for j = 1:time_size
            [position,velocity] = states(obj.sat,timeRange(j),"CoordinateFrame","ecef");
            Satpos(j).posvel = [reshape(position, 3, numSatellites)',reshape(velocity, 3, numSatellites)'];
            Satpos(j).time = timeRange(j);
            waitbar(j / time_size, h, sprintf('仿真卫星位置速度: %d%%', round(j / time_size * 100)));
        end
        obj.timerange = timeRange;
        obj.satpos = Satpos;
        % obj.setsatpos(Satpos);
        close(h);
        disp(['共成功获取',num2str(time_size),'个历元的卫星位置速度']);
      end
   end
  methods 
    % function setsatpos(obj, newValue)
    %     obj.satpos = newValue; % 设置属性值
    % end
    function obj = add_satpos_res(obj)
        disp("正在添加卫星位置速度误差");
        for i = 1:length(obj.satpos)
            % for j = 1:length(obj.satpos(i).posvel(:,1))
            %     obj.satpos_post_res(i).posvel(j,1:3) ...
            %         = obj.satpos(i).posvel(j,1:3)+normrnd(0,obj.satpos_sigma);
            %     obj.satpos_post_res(i).posvel(j,4:6) ...
            %         = obj.satpos(i).posvel(j,4:6)+normrnd(0,obj.satvel_sigma);
            %     obj.satpos_post_res(i).time = obj.satpos(i).time;
            % end
            obj.satpos_post_res(i).posvel(:,1:3) ...
                = obj.satpos(i).posvel(:,1:3)+normrnd(0,obj.satpos_sigma);
            obj.satpos_post_res(i).posvel(:,4:6) ...
                = obj.satpos(i).posvel(:,4:6)+normrnd(0,obj.satvel_sigma);
            obj.satpos_post_res(i).time = obj.satpos(i).time;
        end
        disp(['位置误差方差：',num2str(obj.satpos_sigma),'m']);
        disp(['速度误差方差：',num2str(obj.satvel_sigma),'m/s']);
    end
    function obj = add_TU_res(obj)
        %给每颗卫星添加频偏
    end
  end
end    

